package huajiu.com.utlis;

import java.util.Map;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class ServiceUtil {
	public static String post(String url, Map<String, String> form) {
		try {
			HttpClient client = new HttpClient();
			PostMethod method = new PostMethod(url);
			method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			NameValuePair[] postData = new NameValuePair[form.size()];
			int i = 0;
			for (Map.Entry<String, String> entry : form.entrySet()) {
				postData[i] = new NameValuePair(entry.getKey(), entry.getValue());
				i++;
			}
			method.setRequestBody(postData);
			client.executeMethod(method);
			String result = new String(method.getResponseBody(), "utf-8");
			method.releaseConnection();
			return result;
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
		return "";
	}


}
